package com.ybwh.springboot2.seq.controller;

import com.ybwh.springboot2.common.RespData;
import com.ybwh.springboot2.seq.service.SeqNoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author saytime
 * @since 2018-12-06
 */
@Api(tags = "序列号")
@RestController
@RequestMapping("/seq")
public class SeqNoController {

    @Autowired
    private SeqNoService seqNoService;

    @ApiOperation(value = "雪花算法ID", notes = "")
    @RequestMapping(value = "/snowflake", method = RequestMethod.GET)
    public RespData<Long> snowflake() {
        Long id = seqNoService.getSnowflakeId();

        return RespData.successResp(id);
    }


    @ApiOperation(value = "整齐递增业务编号", notes = "")
    @RequestMapping(value = "/busiNo", method = RequestMethod.GET)
    public RespData<String> busiNo() {

        Map<String, String> param = new HashMap<>(1);
        param.put("date", LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")));

        String no = seqNoService.getBusiNo("TXEXE-{date}", 10, param);

        return RespData.successResp(no);
    }


}
